package vip.xiaonuo.smzq.modular.lifecycle.controller.entity;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

import java.util.stream.Collectors;
import java.util.Date;

import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.smzq.modular.lifecycle.constant.WebResultStatusConstant;
import vip.xiaonuo.smzq.modular.lifecycle.entity.HisiKs;
import vip.xiaonuo.smzq.modular.lifecycle.mapper.entity.HisiKsMapper;
import vip.xiaonuo.smzq.modular.lifecycle.result.ResultWrapper;
import vip.xiaonuo.smzq.modular.lifecycle.result.WebResult;
import vip.xiaonuo.smzq.modular.lifecycle.service.entity.HisiKsService;

/**
 * <p>
 * 矿山信息 前端控制器
 * </p>
 *
 * @author 于彦飞
 * @since 2024-05-09
 */
@CrossOrigin(origins = "*", maxAge = 3600)
@Api(tags = {"矿山信息模块"})
@RestController("lifeCycleHisiKsController")
@RequestMapping("/hisiKs" )
public class HisiKsController {
    @Autowired
    private HisiKsService hisiKsService;
    @Autowired
    private HisiKsMapper hisiKsMapper;
    @Resource
    ResultWrapper resultWrapper;


    @ApiOperation(value = "查询所有矿山信息接口", notes = "查询所有矿山信息接口")
    @PostMapping(value = "/list")
    public WebResult queryHisiKsList(@RequestBody HisiKs hisiKs) {

        return resultWrapper.getSuccessWebResult(hisiKsService.queryHisiKsList(hisiKs));
    }


    @ApiOperation(value = "分页查询矿山信息接口", notes = "分页查询矿山信息接口")
    @PostMapping(value = "/list/page")
    public WebResult queryHisiKsListPage(@RequestBody HisiKs hisiKs) {

        return resultWrapper.getSuccessWebResult(hisiKsService.queryHisiKsListPage(hisiKs));
    }




    @ApiOperation(value = "根据id查询矿山信息接口", notes = "根据id查询矿山信息接口")
    @GetMapping(value = "byId/{id}")
    public WebResult queryHisiKsById(@PathVariable("id") String id) {

        HisiKs entity  = hisiKsService.getById(id);
//        DictConvertUtil.convertToDictionary(entity,null);

        return resultWrapper.getSuccessWebResult(entity);
    }


    @ApiOperation(value = "根据id删除矿山信息接口", notes = "根据id删除矿山信息接口")
    @PostMapping(value = "d/{id}")
    public WebResult delById(@PathVariable("id")String id) {
        return resultWrapper.getWebResultByDelSuccess(hisiKsService.delHisiKs(id));
    }


    @ApiOperation(value = "根据id批量删除矿山信息接口", notes = "根据id批量删除矿山信息接口")
    @PostMapping(value = "/d/batch")
    public WebResult delById(@RequestBody List<String> ids) {
        return resultWrapper.getWebResultByDelSuccess(hisiKsService.delHisiKsBatch(ids));
    }


    @ApiOperation(value = "新增矿山信息接口", notes = "新增矿山信息接口")
    @PostMapping(value = "/save")
    public WebResult save(@RequestBody HisiKs hisiKs) {
        boolean isSuccess = hisiKsService.save(hisiKs);
        if(isSuccess){
            return resultWrapper.getWebResultByWebResultStatusConstant(WebResultStatusConstant.SUCCESS_OPERATION, hisiKs.getId());
        }
        return resultWrapper.getWebResultByWebResultStatusConstant(WebResultStatusConstant.PROCESS_CREATE, null);
    }


    @ApiOperation(value = "批量新增矿山信息接口", notes = "批量矿山信息接口")
    @PostMapping(value = "save/batch")
    public WebResult saveBath(@RequestBody List<HisiKs> hisiKss) {
        boolean isSuccess = hisiKsService.saveBatch(hisiKss);
        if(isSuccess){
            List<Long> ids = hisiKss.stream().map(ele->ele.getId()).collect(Collectors.toList());
            return resultWrapper.getWebResultByWebResultStatusConstant(WebResultStatusConstant.SUCCESS_OPERATION, ids);
        }
        return resultWrapper.getWebResultByWebResultStatusConstant(WebResultStatusConstant.PROCESS_CREATE, null);
    }


    @ApiOperation(value = "更新用户接口", notes = "id必须有值")
    @PostMapping(value = "/update")
    public WebResult update(@RequestBody HisiKs hisiKs) {
        return resultWrapper.getWebResultByEditSuccess(hisiKsService.updateById(hisiKs));
    }

    @ApiOperation(value = "批量更新矿山信息接口", notes = "id必须有值")
    @PostMapping(value = "/update/batch")
    public WebResult updateBatch(@RequestBody List<HisiKs> hisiKss) {
        return resultWrapper.getWebResultByCreateSuccess(hisiKsService.updateBatchById(hisiKss));
    }

    @ApiOperation(value = "新增或者更新接口", notes = "id无值为新增反之则为更新")
    @PostMapping(value = "/saveOrUpdate")
    public WebResult saveOrUpdate(@RequestBody HisiKs hisiKs) {

        return resultWrapper.getSuccessWebResult(hisiKsService.saveOrUpdate(hisiKs));
    }

    @ApiOperation(value = "批量新增或者更新接口", notes = "id无值为新增反之则为更新")
    @PostMapping(value = "/saveOrUpdate/batch")
    public WebResult saveOrUpdate(@RequestBody List<HisiKs> hisiKss) {

        return resultWrapper.getSuccessWebResult(hisiKsService.saveOrUpdateBatch(hisiKss));
    }

}
